window.onload=function () {
    var app = new Vue({
        el: "#app",
        data: {
            pagination: {
                total: 0, //总记录数
                pageSize: 10, //每页的记录数
                pageNum: 1, //当前页码
            },
            tablefunction:[],
            statevalue:false,
            myfunction:{
                fid:0,
                state:0,
                name:"",
                values:""
            },
            addfunctionvalue:false,
            sysfunction:{
                name:"",
                url:"",
                operate:"",
                pid:"",
                type:0
            },
            addsubmodulesvalue:false,
            addsubmodulesvaluename:"",
            updatesfunction:false,
            updatevalueobj:{
                name:"",
                url:"",
                operate:"",
                fid:"",
                state:""
            },
            deletevalue:false,
            deleteobj:{
                fid:"",
                name:""
            }

        },
        methods: {
            inisfunction(){
                //初始化数据
                methodaxios.get(null,"/function/rule?currentPage="+this.pagination.pageNum+"&pageSize="+this.pagination.pageSize,rep=>{
                    this.tablefunction=rep.data.data.data;
                    this.pagination.total=rep.data.data.total;
                });
            },
            //当前页发送改变
            findBlogPageList(page) {
                //页数改变
                this.pagination.pageNum = page;
                this.inisfunction();
            },
            //每页大小发送改变
            sizeChange(size) {
                this.pagination.pageSize = size; //当前页显示多少
                this.pagination.pageNum = 1;
                this.inisfunction();
            }, myswitch(row){//点击禁用按钮
                if(row.state==1){
                    this.myfunction.state=0
                    this.myfunction.values="启用"
                }else{
                    this.myfunction.state=1
                    this.myfunction.values="禁用"
                }
                this.myfunction.fid=row.fid;
                this.myfunction.name=row.name;
                this.statevalue=true
            }, updatefunctionstate(){//点击确定修改状态按钮
                methodaxios.post("/function/update",this.myfunction,rep=>{
                    if(rep.data.code==="200"){
                        this.statevalue=false
                        this.inisfunction();
                        layer.msg("状态修改成功");
                    }
                });
            },
            addfunction(){//点击增加按钮
                this.addfunctionvalue=true
                this.sysfunction.type=10
            },
            confirmaddfunction(){//确定增加
                if(isBlank(this.sysfunction.name)){
                    layer.msg("请输入权限名称名称");
                    return false;
                }
                if(isBlank(this.sysfunction.operate)){
                    layer.msg("请输入权限标识");
                    return false;
                }
                if(isBlank(this.sysfunction.url)){
                    layer.msg("请输入组件路径");
                    return false;
                }
                methodaxios.post("/function/add",this.sysfunction,rep=>{
                    if(rep.data.code==="200"){
                        this.addfunctionvalue=false
                        this.addsubmodulesvalue=false
                        this.inisfunction();
                        this.sysfunction=""
                        this.sysfunction={}
                        layer.msg("新增成功");
                    }
                });
            },
            addsubmodules(fid,name){//添加子模块
                this.sysfunction.pid=fid;
                this.addsubmodulesvaluename=name;
                this.addsubmodulesvalue=true
                this.addfunctionvalue=true
                this.sysfunction.type=20
            },
            updatefunctions(row){//点击修改按钮
                window.console.log(row)
                this.updatesfunction=true
                this.updatevalueobj.name=row.name
                this.updatevalueobj.url=row.url
                this.updatevalueobj.operate=row.operate
                this.updatevalueobj.fid=row.fid
                this.updatevalueobj.state=row.state
                window.console.log("我进来了")
                window.console.log(this.updatevalueobj)
            },
            confirmupdatefunction(){
                if(isBlank(this.updatevalueobj.name)){
                    layer.msg("请输入权限名称名称");
                    return false;
                }
                if(isBlank(this.updatevalueobj.operate)){
                    layer.msg("请输入权限标识");
                    return false;
                }
                if(isBlank(this.updatevalueobj.url)){
                    layer.msg("请输入组件路径");
                    return false;
                }
                methodaxios.post("/function/updatefunction",this.updatevalueobj,rep=>{
                    if(rep.data.code==="200"){
                        this.updatesfunction=false
                        this.inisfunction();
                        this.updatevalueobj={}
                        layer.msg("修改成功");
                    }
                });
            },
            updatemyswitch(){
                if( this.updatevalueobj.state==1){
                    this.updatevalueobj.state=0
                }else{
                    this.updatevalueobj.state=1
                }
            },
            deletefunction(fid,name){
                this.deleteobj.fid=fid
                this.deleteobj.name=name;
                this.deletevalue=true
            },
            confirmdeletefun(){
                methodaxios.get({fid: this.deleteobj.fid},"/function/delete",rep=>{
                    this.deletevalue=false
                    this.inisfunction();
                    layer.msg("删除成功");
                    this.deleteobj={}
                })
            }
        },mounted() {
            this.inisfunction();
        },
        filters:{
            mytime(value){
                var dateee = new Date( value).toJSON();
                return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
            }
        }

    })
}
